package com.hustzp.com.xichuangzhu.utils;

import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

public class ScreenUtils {  

	private static final String TAG = "ScreenUtils";
	private static final boolean DEBUG = false;
	
	private static ScreenSize ss = null;
	
	public static int getScreenWidth(Activity activity) {
		return activity.getWindowManager().getDefaultDisplay().getWidth();
	}
	
	public static int getScreenHeight(Activity activity) {
		return activity.getWindowManager().getDefaultDisplay().getHeight();
	}
	
	public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale);
    }
	
    public static class ScreenSize{
    	public int width;
    	public int height;
    }
	//获取屏幕的宽度
	public static int getScreenWidth(Context context) {
		WindowManager manager = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		Display display = manager.getDefaultDisplay();
		return display.getWidth();
	}
	//获取屏幕的高度
	public static int getScreenHeight(Context context) {
		WindowManager manager = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		Display display = manager.getDefaultDisplay();
		return display.getHeight();
	}
	/**
     * 获取屏幕长宽像素
     * @param activity
     * @return
     */
    public static ScreenSize getScreenSizeInfo(Activity activity){
    	
    	if(ss == null){
    		ss = new ScreenSize();
			DisplayMetrics dm = new DisplayMetrics();
			activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
			ss.width = dm.widthPixels;//宽度
			ss.height = dm.heightPixels ;//高度
    	}
		return ss;
    }
}